<?php
use yii\widgets\LinkPager;
use yii\helpers\Url;

//接受页码
$page=isset($_GET['page']) ? $_GET['page'] : 1;
//实例化redis
$redis = new Redis();
//连接
$redis->pconnect("127.0.0.1",6379);
//指定库
$redis->select("14");
if ($redis->hExists("goods","page$page")){
    echo "这是redis内中的数据";
    //取出redis内数据 此时为JSON 数据 要转化形式
    $data=$redis->hGet("goods","page$page");
    //替换  解码
    $models=json_decode($data,true);
}else{
    echo "这些数据是数据库读取出来的";
    //设置值
    $redis->hSet("goods","page$page",json_encode($models));
}



?>

<form action="<?php echo Url::toRoute('demo/show');?>" method="post">
    <input type="text" name="val">
    <input type="hidden" name="_csrf" value="<?php echo Yii::$app->request->csrfToken?>">
    <input type="submit" value="搜索">
</form>

<table>
    <tr>
        <td>商品ID</td>
        <td>商品名称</td>
        <td>商品价格</td>
        <td>商品库存</td>
        <td>品牌名称</td>
        <td>分类名称</td>
        <td>商品图片</td>
        <td>操作</td>
    </tr>
    <?php foreach ($models as $key=>$value){ ?>
    <tr>
        <td><?php echo $value['goods_id']?></td>
        <td><?php echo $value['goods_name']?></td>
        <td><?php echo $value['goods_price']?></td>
        <td><?php echo $value['goods_stock']?></td>
        <td><?php echo $value['brand_name']?></td>
        <td><?php echo $value['type_name']?></td>
        <td><img src="<?php echo $value['goods_img']?>" alt="" width="100px" height="100px"></td>
        <td><a href="<?php echo Url::toRoute('demo/info');?>&id=<?php echo $value['goods_id']?>">详情页</a></td>
    </tr>
    <?php }?>
</table>











<?php
// 显示分页
echo LinkPager::widget([
    'pagination' => $pages,
]);


?>
